#include<iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
using namespace std;
//int mkfifo(const char *pathname, mode_t mode);

int main()
{
    //创建命名管道文件
    char namedpipe[]="named_pipe";
    int ret=mkfifo(namedpipe,0666);
    if(ret==-1)
    {
        cerr<<"mkfifo err"<<endl;
        return 1;
    }
    //以写的方式
    int fd=open(namedpipe,O_CREAT|O_WRONLY,0644);
    if(fd==-1)
    {
        cerr<<"open err"<<endl;
        return 2;
    }
    while(true)
    {
        string message;
        cout<<"请输入要发送的消息:"<<endl;
        cin>>message;
        int n=write(fd,message.c_str(),message.size());
        if(n==-1)
        {
            cerr<<"write err"<<endl;
            return 3;
        }
    }
    return 0;
}